package com.lcj.aoch.rule.controller;

import com.lcj.aoch.rule.config.ConstantConfiguration;
import com.lcj.aoch.rule.controller.form.CalculateDriverCancelOrderForm;
import com.lcj.aoch.rule.controller.form.SearchCancelRuleByIdForm;
import com.lcj.aoch.rule.service.CancelRuleService;
import com.lcj.common.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.HashMap;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/cancel"})
@Tag(name = "CancelRuleController", description = "订单取消的Web接口")
public class CancelRuleController {
  
  @Resource
  private CancelRuleService cancelRuleService;

  @Resource
  private ConstantConfiguration constantConfiguration;

  @PostMapping({"/calculateDriverCancelOrder"})
  @Operation(summary = "计算司机取消订单")
  public Result calculateDriverCancelOrder(@RequestBody @Valid CalculateDriverCancelOrderForm a) {
    String status = a.getStatus();
    short cancelNum = a.getCancelNum().shortValue();
    short acceptMinute = a.getAcceptMinute().shortValue();
    short waitingMinute = a.getWaitingMinute().shortValue();
    HashMap var7 = this.cancelRuleService.calculateDriverCancelOrder(status, cancelNum, acceptMinute, waitingMinute, constantConfiguration.getAesKey());
    return Result.ok().put("result", var7);
  }
  
  @PostMapping({"/searchCancelRuleById"})
  @Operation(summary = "根据ID查询取消规则")
  public Result searchCancelRuleById(@RequestBody @Valid SearchCancelRuleByIdForm searchCancelRuleByIdForm) {
    return Result.ok().put("result", this.cancelRuleService.searchCancelRuleById(searchCancelRuleByIdForm.getRuleId().longValue()));
  }
}
